﻿package cn.antscript.airCMS.display.component.btnbase 
{
	import cn.antscript.airCMS.data.IGroupBtn;
	import cn.antscript.airCMS.data.singleData.AbstractData;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.BevelFilter;
	import flash.filters.DropShadowFilter;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	/**
	 * ...
	 * @author 
	 */
	public class GroupBtn extends Sprite
	{		
		private static var _format:TextFormat = new TextFormat("Arial", 14, 0xaaaaaa);
		private var _txt:TextField;
		
		public var data:Object;
		
		public function GroupBtn(data_:Object=null,container:DisplayObjectContainer=null,xPos:int=0,yPos:int=0)
		{
			if (container != null) {
				container.addChild(this);
			}
			this.x = xPos;
			this.y = yPos;
			
			this.data = data_;
			
			_txt = new TextField();
			_txt.width = 635;
			_txt.height = 30;
			_txt.text = data["label"];
			_txt.setTextFormat(_format);
			_txt.selectable = false;
			_txt.x = 20;
			_txt.y = 5;
			addChild(_txt);
				
			this.graphics.beginFill(0x666666);
			this.graphics.drawRect(0, 0, _txt.width+40, 30);
			this.graphics.endFill();
			
			
			this.mouseChildren = false;
			this.buttonMode = true;
			
			this.addEventListener(MouseEvent.ROLL_OVER, onOver);
			this.addEventListener(MouseEvent.ROLL_OUT, onOut);
			
			this.addEventListener(Event.REMOVED_FROM_STAGE, onRemove);
		}
		
		private function onRemove(e:Event):void 
		{
			removeEventListener(Event.REMOVED_FROM_STAGE, onRemove);
			
			this.removeEventListener(MouseEvent.ROLL_OVER, onOver);
			this.removeEventListener(MouseEvent.ROLL_OUT, onOut);
			
			data = null;
		}
		
		
		
		private function onOver(e:MouseEvent):void 
		{
			this.graphics.clear();
			this.graphics.lineStyle(2, 0xaaaaaa);
			this.graphics.beginFill(0x111111);
			this.graphics.drawRect(0, 0, _txt.width+40, 30);
			this.graphics.endFill();
			
			if (_txt.width < _txt.textWidth) {
				addEventListener(Event.ENTER_FRAME, onEnter);
			}
			
		}
		
		private function onEnter(e:Event):void
		{
			
			_txt.scrollH += 1;
			if (_txt.scrollH == _txt.maxScrollH) {
				removeEventListener(Event.ENTER_FRAME, onEnter);
			}
		}
		
		private function onOut(e:MouseEvent):void 
		{
			this.graphics.clear();
			this.graphics.beginFill(0x666666);
			this.graphics.drawRect(0, 0, _txt.width+40, 30);
			this.graphics.endFill();
			
			_txt.scrollH = 0;
			removeEventListener(Event.ENTER_FRAME, onEnter);
		}
		
		
		
	}

}